Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent diagnostics on .NET SDK 8.0.100 #2049

Merged
merged 3 commits into from
Nov 22, 2023
Merged

Conversation

idg10
Copy link
Collaborator

@idg10 idg10 commented Nov 21, 2023

The .NET SDK 8.0.100 adds various new diagnostics. Some of these relate to new language features in C# 12.0, and some are just part of the ongoing tendency for the SDK to notice ever more issues.

This updates the code to use C# 12.0 collection expressions except in one case: we aren't currently big fans of IDE0305, which wants to transform all uses of x.ToArray() to [.. x]. This seems a little obscure. Possibly it will seem more natural in a few years when we're used to seeing collection expressions. Or possibly not—use of spreads in these expressions might be a less mainstream technique.

After some deliberation we've also elected to disable IDE0290, which wants us to use primary constructors. Although there are some cases where its suggestions seem like a clear improvement, in some they are not. In particular, when types have multiple constructors but the diagnostic has determined that use of this(...) means its able to designate one as a primary constructor, it often just looks a bit odd. The decision to use this(...) is often an implementation choice, and the constructor elevated to be the 'primary' one often looks a bit arbitrary as a result. Unless and until some way of making this rule more selective can be found, we are going to leave it switched off.

* disabled several entirely
* fixed some easy ones
In most cases, we now just use the new (C# 12.0) collection expression syntax. However, we've disabled IDE0305 because it makes suggestions that aren't an obvious improvement. It wants to rewrite use of ToArray() to be a collection expression. E.g. something.ToArray() would become [.. something]. Perhaps that will seem natural once we've all got used to spreads in collection expressions, but to me (idg10) today that looks odd.
Make UWP test runner use the same warning settings as everything else, except for CS0618, which a large number of tests appear to depend on.
@idg10 idg10 changed the title Prevent diagnostic on .NET SDK 8.0.100 Prevent diagnostics on .NET SDK 8.0.100 Nov 21, 2023
@idg10 idg10 merged commit 57e4c42 into main Nov 22, 2023
7 checks passed
@idg10 idg10 deleted the feature/80sdk-diagnostics branch November 22, 2023 09:32
idg10 added a commit that referenced this pull request May 21, 2024
Address collection expression diagnostics

In most cases, we now just use the new (C# 12.0) collection expression syntax. However, we've disabled IDE0305 because it makes suggestions that aren't an obvious improvement. It wants to rewrite use of ToArray() to be a collection expression. E.g. something.ToArray() would become [.. something]. Perhaps that will seem natural once we've all got used to spreads in collection expressions, but to me (idg10) today that looks odd.

Add comment explaining why we've disable IDE0290

Make UWP test runner use the same warning settings as everything else, except for CS0618, which a large number of tests appear to depend on.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants